/**
 * @author:linjiye
 * @date: 2025/1/3
 * @desc:
 **/

import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import React, {useEffect, useState} from 'react'
import PageFormBtn from "@/components/PageFormBtn";
import PageScrollView from "@/components/PageScrollView";
import FcButton from "@/components/FcButton";
import MorePlatformsWrap from "@/components/morePlatforms/MorePlatformsWrap";
import {useRouter} from "expo-router";
import {useSelector} from "react-redux";
import useApiOfSSE from "@/hooks/useApiOfSSE";
import {useMmContentManagePubAddMutation} from "@/store/api/aiOriginality/aiOriginalityApi";
import {Toast} from "@ant-design/react-native";

type Props = {}

const result = (props: Props) => {
    const [params, setParams] = useState({})

    const [text, setText] = useState('')
    const router = useRouter();

    const [addFun] = useMmContentManagePubAddMutation()

    let p = useSelector(state => state.morePlatforms.params)
    useEffect(() => {
        setParams(p)
        console.log(params,'-----============------------');


    }, [params,p])



    function handleAdd() {
        let params = {
            content: text,
            templateId: "1749679210634153986",
            title: null
        }
        addFun(params).then(({data: {code, result}}) => {
            console.log(code, result);
            if (code === 200) Toast.info(result)
        })
    }

    function generatedText() {
        router.navigate(`/aiOriginality/result?fromWay=morePlatformsPage`)
    }

    return (
        <PageScrollView
            isHaveHeader
            isTransparentTab
            pageBottom={
                <View>
                    <View style={styles.bottom_btn}>
                        <View style={{flex: 1, marginRight: 4}}>
                            <FcButton
                                onClick={() => handleAdd()}
                                disable={!params?.text}
                                type='default'
                                style={{
                                    width: '100%',
                                    height: 40,
                                    justifyContent: 'center',
                                    backgroundColor: '#F1F2F4',
                                    borderRadius: 8
                                }}
                                itemStyle={{fontSize: 15}}
                                textName='导入内容管理'/>
                        </View>
                        <View style={{flex: 1, marginLeft: 4}}>
                            <FcButton
                                disable={!params?.text}
                                onClick={() => generatedText()}
                                type='BjJB'
                                colors={['#6989FF', '#C65EFD']}
                                style={{width: '100%', height: 40, justifyContent: 'center'}}
                                itemStyle={{borderRadius: 8, fontSize: 15}}
                                textName='生成文案'/>
                        </View>
                    </View>
                </View>
            }
        >
            <MorePlatformsWrap />
        </PageScrollView>
    )
}

export default result

const styles = StyleSheet.create({
    bottom_btn: {
        flexDirection: "row",
        alignItems: "center",
        paddingHorizontal: 16,
        height: 56,
        justifyContent: "space-between",
        backgroundColor: 'white'
    },

    btn_wrap: {
        flexDirection: "row",
        alignItems: "center",
        padding: 12,
        backgroundColor: 'white',
        marginBottom: 8,
        borderTopWidth: 0.5,
        borderTopColor: 'rgba(0, 0, 0, 0.1)',
    },
    btn: {
        flexDirection: "row",
        alignItems: "center",
        backgroundColor: '#F1F2F4',
        borderRadius: 8,
        paddingHorizontal: 8,
        height: 28,
        marginRight: 8
    },
})